<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学号
" prop="num">
        <el-input
          v-model="queryParams.num"
          placeholder="请输入学号
"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="身份证号" prop="idcard">
        <el-input
          v-model="queryParams.idcard"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级简称" prop="cid">
        <el-input
          v-model="queryParams.cid"
          placeholder="请输入班级简称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属学院" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入所属学院"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业" prop="majId">
        <el-input
          v-model="queryParams.majId"
          placeholder="请输入专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年级" prop="grade">
        <el-input
          v-model="queryParams.grade"
          placeholder="请输入年级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="层级" prop="hierarchy">
        <el-input
          v-model="queryParams.hierarchy"
          placeholder="请输入层级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学制" prop="lengthSchool">
        <el-input
          v-model="queryParams.lengthSchool"
          placeholder="请输入学制"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="家庭地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入家庭地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否在校" prop="inschool">
        <el-select v-model="queryParams.inschool" placeholder="请选择是否在校" clearable>
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否走读" prop="dayschool">
        <el-select v-model="queryParams.dayschool" placeholder="请选择是否走读" clearable>
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="寝室号" prop="bedroom">
        <el-input
          v-model="queryParams.bedroom"
          placeholder="请输入寝室号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理日期" prop="CLRQ">
        <el-date-picker clearable
          v-model="queryParams.CLRQ"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择处理日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="操作类型" prop="CZLX">
        <el-input
          v-model="queryParams.CZLX"
          placeholder="请输入操作类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数据来源" prop="SJLY">
        <el-input
          v-model="queryParams.SJLY"
          placeholder="请输入数据来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用1" prop="BY1">
        <el-input
          v-model="queryParams.BY1"
          placeholder="请输入备用1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用2" prop="BY2">
        <el-input
          v-model="queryParams.BY2"
          placeholder="请输入备用2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['student:stu_message:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['student:stu_message:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['student:stu_message:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['student:stu_message:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="stu_messageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="sid" align="center" prop="sid" />
      <el-table-column label="学号
" align="center" prop="num" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="身份证号" align="center" prop="idcard" />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="班级简称" align="center" prop="cid" />
      <el-table-column label="所属学院" align="center" prop="deptId" />
      <el-table-column label="专业" align="center" prop="majId" />
      <el-table-column label="年级" align="center" prop="grade" />
      <el-table-column label="层级" align="center" prop="hierarchy" />
      <el-table-column label="学制" align="center" prop="lengthSchool" />
      <el-table-column label="家庭地址" align="center" prop="address" />
      <el-table-column label="是否在校" align="center" prop="inschool">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.inschool"/>
        </template>
      </el-table-column>
      <el-table-column label="是否走读" align="center" prop="dayschool">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.dayschool"/>
        </template>
      </el-table-column>
      <el-table-column label="寝室号" align="center" prop="bedroom" />
      <el-table-column label="处理日期" align="center" prop="CLRQ" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.CLRQ, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作类型" align="center" prop="CZLX" />
      <el-table-column label="数据来源" align="center" prop="SJLY" />
      <el-table-column label="备用1" align="center" prop="BY1" />
      <el-table-column label="备用2" align="center" prop="BY2" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['student:stu_message:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['student:stu_message:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改学生信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学号
" prop="num">
          <el-input v-model="form.num" placeholder="请输入学号
" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="身份证号" prop="idcard">
          <el-input v-model="form.idcard" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="班级简称" prop="cid">
          <el-input v-model="form.cid" placeholder="请输入班级简称" />
        </el-form-item>
        <el-form-item label="所属学院" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入所属学院" />
        </el-form-item>
        <el-form-item label="专业" prop="majId">
          <el-input v-model="form.majId" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="年级" prop="grade">
          <el-input v-model="form.grade" placeholder="请输入年级" />
        </el-form-item>
        <el-form-item label="层级" prop="hierarchy">
          <el-input v-model="form.hierarchy" placeholder="请输入层级" />
        </el-form-item>
        <el-form-item label="学制" prop="lengthSchool">
          <el-input v-model="form.lengthSchool" placeholder="请输入学制" />
        </el-form-item>
        <el-form-item label="家庭地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入家庭地址" />
        </el-form-item>
        <el-form-item label="是否在校" prop="inschool">
          <el-radio-group v-model="form.inschool">
            <el-radio
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否走读" prop="dayschool">
          <el-radio-group v-model="form.dayschool">
            <el-radio
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="寝室号" prop="bedroom">
          <el-input v-model="form.bedroom" placeholder="请输入寝室号" />
        </el-form-item>
        <el-form-item label="处理日期" prop="CLRQ">
          <el-date-picker clearable
            v-model="form.CLRQ"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择处理日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="操作类型" prop="CZLX">
          <el-input v-model="form.CZLX" placeholder="请输入操作类型" />
        </el-form-item>
        <el-form-item label="数据来源" prop="SJLY">
          <el-input v-model="form.SJLY" placeholder="请输入数据来源" />
        </el-form-item>
        <el-form-item label="备用1" prop="BY1">
          <el-input v-model="form.BY1" placeholder="请输入备用1" />
        </el-form-item>
        <el-form-item label="备用2" prop="BY2">
          <el-input v-model="form.BY2" placeholder="请输入备用2" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStu_message, getStu_message, delStu_message, addStu_message, updateStu_message } from "@/api/student/stu_message";

export default {
  name: "Stu_message",
  dicts: ['sys_yes_no', 'sys_user_sex'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学生信息表格数据
      stu_messageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        num: null,
        name: null,
        sex: null,
        idcard: null,
        phone: null,
        cid: null,
        deptId: null,
        majId: null,
        grade: null,
        hierarchy: null,
        lengthSchool: null,
        address: null,
        inschool: null,
        dayschool: null,
        bedroom: null,
        CLRQ: null,
        CZLX: null,
        SJLY: null,
        BY1: null,
        BY2: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询学生信息列表 */
    getList() {
      this.loading = true;
      listStu_message(this.queryParams).then(response => {
        this.stu_messageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        sid: null,
        num: null,
        name: null,
        sex: null,
        idcard: null,
        phone: null,
        cid: null,
        deptId: null,
        majId: null,
        grade: null,
        hierarchy: null,
        lengthSchool: null,
        address: null,
        inschool: null,
        dayschool: null,
        bedroom: null,
        CLRQ: null,
        CZLX: null,
        SJLY: null,
        BY1: null,
        BY2: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学生信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const sid = row.sid || this.ids
      getStu_message(sid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改学生信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.sid != null) {
            updateStu_message(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStu_message(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const sids = row.sid || this.ids;
      this.$modal.confirm('是否确认删除学生信息编号为"' + sids + '"的数据项？').then(function() {
        return delStu_message(sids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('student/stu_message/export', {
        ...this.queryParams
      }, `stu_message_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
